/*
 * DMA.c
 *
 *  Created on: 2021年2月22日
 *      Author: 78677
 */

#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"


void DMA_CH1_Timer_Init(volatile Uint16 *DMA_Dest,volatile Uint16 *DMA_Source){
        DMACH1AddrConfig(DMA_Dest,DMA_Source);
        DMACH1BurstConfig(10,1,1);         //Will set up to use 32-bit datasize, pointers are based on 16-bit words
        DMACH1TransferConfig(1,0,0);      //so need to increment by 2 to grab the correct location
        DMACH1WrapConfig(0xFFFF,0,0xFFFF,0);  // 禁用wrap传输
        DMACH1ModeConfig(DMA_TINT0,PERINT_ENABLE,ONESHOT_ENABLE,CONT_DISABLE,SYNC_DISABLE,
                         SYNC_SRC,OVRFLOW_DISABLE,SIXTEEN_BIT,CHINT_END,CHINT_ENABLE);
        StartDMACH1();
        CpuTimer0.RegsAddr = &CpuTimer0Regs;
        ConfigCpuTimer(&CpuTimer0, 150, 500);  // 100s中断
        CpuTimer0Regs.TCR.bit.TSS = 0;
}



volatile Uint16 *DMADest;
volatile Uint16 *DMASource;

#pragma DATA_SECTION(ADC_Value,"DMARAML1")
Uint16 ADC_Value[20];

#pragma DATA_SECTION(New_Value,"DMARAML2")
Uint16 New_Value[20];

__interrupt void DMA_CH1_Interrupt(){
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP7;  // 第7组中断响应
    for(;;);
}

void main(void){
    int i;
    InitSysCtrl();
    DINT;
    InitPieCtrl();
    InitPieVectTable();
    IER = 0x0000;
    IFR = 0x0000;
    EALLOW;
    PieVectTable.DINTCH1 = &DMA_CH1_Interrupt;
    EDIS;

    PieCtrlRegs.PIEIER7.bit.INTx1 = 1;
    IER |= M_INT7;
    EnableInterrupts();
    for(i=0;i<20;i++){
        ADC_Value[i]=i;
        New_Value[i]=0;
    }
    DMASource   = ADC_Value;        // DMA 目标地址
    DMADest = New_Value; // 源地址
    DMA_CH1_Timer_Init(DMADest,DMASource);

    while(1){}
}















